// pages/order/order-detail/order-detail.js
import { getOrderDetail } from "../../../network/order";
import { callTel } from '../../../utils/Tools'
Page({
  data: {
    order_id:'',
    code:'',
    info:{},
    pics:[],
    status:{
      '0':'审核中','1':'进行中'
    },
    print:{
      '0':'未打印','1':'已打印'
    },
    orderStatus:0,
  },
  onLoad: function (options) {
    
    this.setData({
      order_id: options.order_id,
      code: options.code,
      orderStatus:+options.code
    })

    //    调用网络请求
    this._getOrderDetail()
  },
  //再下一单
  // url='/pages/client/valet-order/valet-order?customer_id={{item.id}}&supplyer_company={{item.supplyer_company}}'
  continues(){
     wx.request({
      url: 'https://master.gddzxcx.com/api/'+'orders/again_order',
      method:'Post',
      data:{
        order_id:+ this.data.order_id,
        token:wx.getStorageSync("token")
      },
      success:res=>{
        if(res.data.code===200){
          let orderList={}
          orderList=JSON.stringify(res.data.data);
          // JSON.stringify(orderList)
          wx.navigateTo({
            url: '/pages/client/valet-order/valet-order?orderList='+orderList
          })
        }else{
          wx.showToast({
            title: res.data.msg,
            icon:'none',
            duration:1500
          })
        }
      },
      fail:err=>{
        console.log(err)
      }
    })
    
   
  },
  handleCallTel(e){ //  拨打电话
    const {phone} = e.currentTarget.dataset
    callTel(phone)
  },
  // 预览图片
  previewImg: function (e) {
    //获取当前图片的下标
    const index = e.currentTarget.dataset.index;
    //所有图片
    const pics = this.data.pics;
    wx.previewImage({
      //当前显示图片
      current: pics[index],
      //所有图片
      urls: pics
    })
  },
  //      网络请求     //
  async _getOrderDetail(){
    console.log(this.data.order_id)
    console.log(this.data.code)
    const data = {
      order_id: this.data.order_id,
      code: this.data.code
    }
    const res = await getOrderDetail(data)
    if(res.code === 200){
      const info = Object.assign({},res.data.info,{product:res.data.product})
      this.setData({
        info,
        pics: res.data.agreement.images
      })
    }
    // console.log(this.data.info)
  }
})